package com.boarsoft.boar.demo.order.biz;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.boarsoft.boar.demo.order.entity.PocTrxMessage;
import com.boarsoft.dao.sharding.bean.DaoSharding;
import com.boarsoft.hibernate.biz.SimpleBizImpl;

@Component("trxMessageBiz")
public class PocTrxMessageBizImpl extends SimpleBizImpl implements PocTrxMessageBiz {

	@Override
	@Transactional
	@DaoSharding(policy = "tenant", index = 0)
	public boolean save(int tenantId, PocTrxMessage message) {
		if (dao.save(message) == null) {
			return false;
		}
		return true;
	}

	@Override
	@DaoSharding(policy = "tenant", index = 0)
	@Transactional
	public boolean trxSave(int tenantId, PocTrxMessage message) {
		if (dao.save(message) == null) {
			return false;
		}
		return true;
	}

	@Override
	@Transactional
	@DaoSharding(policy = "tenant", index = 0)
	public boolean update(int tenantId, PocTrxMessage message) {

		return dao.update(message);

	}

	@Override
	@Transactional(readOnly = true)
	@DaoSharding(policy = "tenant", index = 0)
	public PocTrxMessage findById(int tenantId, String messageId) {

		String string = " and message_id = '" + messageId + "'";

		PocTrxMessage message = dao.find(PocTrxMessage.class, string);

		return message;

	}

	@Override
	@DaoSharding(policy = "tenant", index = 0)
	@Transactional(readOnly = true)
	public List<PocTrxMessage> findAll(int tenantId, String hql, int pageNo, int pageSize) {
		return dao.list(PocTrxMessage.class, hql, pageNo, pageSize);
	}

	@Override
	@Transactional
	@DaoSharding(policy = "tenant", index = 0)
	public void batchUpdate(int tenantId, List<PocTrxMessage> lt) {
		dao.batchUpdate(lt, 50);
	}
}